package base.util;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.math.RandomUtils;

import base.model.SessionModel;

public class Common {
    /**
     * 保存登录时的数据
     */
    private static final ThreadLocal<HttpServletRequest> threadSession = new ThreadLocal<HttpServletRequest>();

    public static SessionModel getSession() {
        HttpServletRequest request = threadSession.get();
        SessionModel ses = (SessionModel) request.getSession().getAttribute("SessionModel");
        return ses;
    }

    public static void setSessionManger(HttpServletRequest request) {
        if (request.getSession().getAttribute("SessionModel") != null) {
            threadSession.set(request);
        }
    }

    /**
     * 生成流水号，应用于订单ID等
     * 
     * @return
     */
    public static String genSeriaNO() {
        return new StringBuilder(String.valueOf(System.nanoTime())).append(RandomUtils.nextInt(10))
                .toString();
    }
}
